package maxAscendingSum;

//public class Solution {
//    public int maxAscendingSum(int[] nums) {
////        // 思路 滑动窗口
////        int r = 1;
////        int l = 0;
////        int max = 0;
////        int[] prevSum = new int[nums.length+1];
////
////        for (int i = 0; i <prevSum.length ; i++) {
////            prevSum[i+1] = prevSum[i] + nums[i];
////        }
////        while (l<nums.length&&r<nums.length){
////            while (nums[r]>=nums[r-1]){
////                r++;
////            }
////            int sum = prevSum[r] - prevSum[l];
////            max = Math.max(sum,max);
////            l = r;
////            r++;
////        }
////        return max;
//    }
//}
class Solution {
    public int maxAscendingSum(int[] nums) {
        int n = nums.length, ans = nums[0];
        for (int i = 1, cur = nums[0]; i < n; i++) {
            if (nums[i] > nums[i - 1]) cur += nums[i];
            else cur = nums[i];
            ans = Math.max(ans, cur);
        }
        return ans;
    }
}
